package com.geeksaga.dao.ibatis.mysql;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.common.util.DateConvertor;
import com.geeksaga.dao.SpecCodeDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.Spec;
import com.geeksaga.domain.SpecCode;

/**
 * @author newbie
 * @since 0.1
 */
@Repository
public class SpecCodeDaoImpl extends BaseIBatisDao implements SpecCodeDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#add(com.geeksaga.domain.SpecCode)
     */
    public SpecCode add(SpecCode specCode) throws DataAccessException {
        specCode.setRegistDate(DateConvertor.getDateFormat());
        specCode.setRegistTime(DateConvertor.getTimeFormat());
        specCode.setRegistTimestamp(DateConvertor.getDateTimeFormat());
        specCode.setModifyDate(DateConvertor.getDateFormat());
        specCode.setModifyTime(DateConvertor.getTimeFormat());
        specCode.setModifyTimestamp(DateConvertor.getDateTimeFormat());
        
        return (SpecCode) getSqlMapClientTemplate().insert("SPEC_CODE.add", specCode);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#find(com.geeksaga.domain.SpecCode)
     */
    public SpecCode find(SpecCode specCode) throws DataAccessException {
        return (SpecCode) getSqlMapClientTemplate().queryForObject("SPEC_CODE.find", specCode);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#findBySpec(com.geeksaga.domain.Spec)
     */
    @SuppressWarnings("unchecked")
    public List<SpecCode> findListBySpec(Spec spec) throws DataAccessException {
        return (List<SpecCode>) getSqlMapClientTemplate().queryForList("SPEC_CODE.findListBySpec", spec);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#modify(com.geeksaga.domain.SpecCode)
     */
    public int modify(SpecCode specCode) throws DataAccessException {
        specCode.setModifyDate(DateConvertor.getDateFormat());
        specCode.setModifyTime(DateConvertor.getTimeFormat());
        specCode.setModifyTimestamp(DateConvertor.getDateTimeFormat());
        
        return getSqlMapClientTemplate().update("SPEC_CODE.update", specCode);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#confirmPassword(com.geeksaga.domain.SpecCode)
     */
    public SpecCode confirmPassword(SpecCode specCode) throws DataAccessException {
        return (SpecCode) getSqlMapClientTemplate().queryForObject("SPEC_CODE.confirmPassword", specCode);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#remove(com.geeksaga.domain.SpecCode)
     */
    public int remove(SpecCode specCode) throws DataAccessException {
        return getSqlMapClientTemplate().delete("SPEC_CODE.remove", specCode);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecCodeDao#updateDelYn(com.geeksaga.domain.SpecCode)
     */
    public int updateDelYn(SpecCode specCode) throws DataAccessException {
        return getSqlMapClientTemplate().update("SPEC_CODE.updateDelYn", specCode);
    }
}